from models import BaseModel
from sqlalchemy import Column, String, Text, JSON, Integer


class Tasks(BaseModel):
    """异步任务模型
    用于存储异步任务的执行过程和结果
    """
    __tablename__ = 'tasks'
    
    task_id = Column(String(50), nullable=False, index=True, comment='任务ID')
    task_type = Column(String(50), nullable=False, comment='任务类型')
    status = Column(String(20), nullable=False, default='pending', comment='任务状态：pending, running, completed, failed')
    message = Column(Text, nullable=True, comment='任务消息或结果描述')
    account_id = Column(String(36), nullable=True, comment='关联的账号ID')
    params = Column(JSON, nullable=True, comment='任务参数')
    result = Column(JSON, nullable=True, comment='任务结果')
    progress = Column(Integer, nullable=True, default=0, comment='任务进度(0-100)')
    error = Column(Text, nullable=True, comment='错误信息')
    started_at = Column(String(30), nullable=True, comment='开始时间')
    finished_at = Column(String(30), nullable=True, comment='完成时间')
